<?php

class UserIdentity extends CUserIdentity
{

/**
 * 登录逻辑处理
 * @return boolean 
 */
	public function authenticate()
	{
		$userInfo = User::model()->findByAttributes(array('username'=>$this->username));

		if(is_null($userInfo)){
			$this->errorCode = self::ERROR_USERNAME_INVALID;
			return false;
		} elseif ($userInfo->password !== md5($this->password)){
			$this->errorCode = self::ERROR_PASSWORD_INVALID;
			return false;
		} else {
			$userInfo->login_time = time();
			$userInfo->login_ip = Yii::app()->request->userHostAddress;
			
			Yii::app()->session['login_time'] = time();
			Yii::app()->session['user_id'] = $userInfo->user_id;
			
			$userInfo->save(false);		//false表示禁止验证
			$this->errorCode = self::ERROR_NONE;
		}
		return true;
	}
}